# -*- coding: utf-8 -*-

from rest_framework.renderers import JSONRenderer
from rest_framework.status import is_success


class BKJSONRenderer(JSONRenderer):

    def render(self, data, accepted_media_type=None, renderer_context=None):
        response = renderer_context["response"]
        if is_success(response.status_code):
            data = {
                "result": True,
                "data": data,
                "message": "OK"
            }
        else:
            data = {
                "result": False,
                "data": None,
                "message": data
            }
        return super(BKJSONRenderer, self).render(data, accepted_media_type, renderer_context)
